// pages/userStatistics/WriteOff/integralDetail/integralDetail.js
const app=getApp();
const Controllers = require('../../../controllers/Controller').controller;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    globalStype:'',
    tab1:true,
    tab2:false,
    moneyData:{},
    amountList:[],
    outList:[],
    value:{
      genre:0,
      shopId:"",
      types:'0,1,3,4,6,7,9',
      amountType:1,
      pageNumber:1
    },
    value2:{
      genre:1,
      shopId:"",
      types:'0,1,3,4,6,7,9',
      amountType:1,
      pageNumber:1
    },
    tabItem:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (option) {
    if(wx.getStorageSync('shopId')){
      this.setData({
        shopId:wx.getStorageSync('shopId')
      })
    }
    if(option.userId){
      this.setData({
        userId:option.userId
      })
    }
    this.setData({
      'value.shopId':wx.getStorageSync('shopId'),
      'value2.shopId':wx.getStorageSync('shopId'),
      'value.accountId':option.userId,
      'value2.accountId':option.userId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getAmountHistory()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getIncomeOrCost()
  },

  /**
   * 用户点击右上角分享
   */
  // 进行tab跳转选项
  selectTab(e){
    var num=e.currentTarget.dataset['index']
   if(num==1){
    this.setData({tab1:true,tab2:false})
    this.setData({
      tabItem:0
    })
   }else{
    this.setData({tab2:true,tab1:false})
    this.setData({
      tabItem:1
    })
   }
  },

  //获取收益消费记录
  getAmountHistory(){
    let value=this.data.value;
    let value2=this.data.value2
    Controllers.amountHistory(value).then(res=>{
      this.setData({
        amountList:res.data.list
      })
    })
    Controllers.amountHistory(value2).then(res=>{
      this.setData({
        outList:res.data.list
      })
    })
  },

  //下滑获取积分充值或者消费的记录
  getIncomeOrCost(){
    let selectItem=this.data.tabItem;
    if(selectItem==0){
      let page=this.data.value.pageNumber;
      page=page+1;
      this.setData({
        'value.pageNumber':page
      })
      Controllers.amountHistory(this.data.value).then(res=>{
        let list1=this.data.amountList;
        let list2=res.data.list;
        let cList=list1.concat(list2);

        this.setData({
          amountList:cList
        })
      })
    }else{
      let page=this.data.value2.pageNumber;
      page=page+1;
      this.setData({
        'value2.pageNumber':page
      })
      Controllers.amountHistory(this.data.value2).then(res=>{
        let list1=this.data.outList;
        let list2=res.data.list;
        let cList=list1.concat(list2);

        this.setData({
          outList:cList
        })
      })
    }
  }
})